//接收数据
function data_accept(res) {
    // for (var k in res.data) {
    // }
    return res;
}
//获取对象中有几个属性的封装方法
function get_attribute(data) {
    let n = 0;
    for (var k in data) {
        n++
    }
    return n
}
//登录成功之后页面变化
var nav_re_lg = document.querySelector('.nav_re_lg');
var user_profile = document.querySelector('.nav_photo_img');
var account_inputs = document.querySelector('.account_setup_banner_form').querySelectorAll('input');
var nav_photo = document.querySelector('.nav_photo');
var my_photo_img = document.querySelector('.my_photo_img');
//让全局变量等于登录传回来的数据
let lg_data = 0;

function lg_change(lg_change_data) {
    lg_data = lg_change_data;
    //nav头像变化
    //将注册/登录更换为头像
    nav_re_lg.style.display = 'none';
    nav_photo.style.display = "flex";
    //个人所有头像的渲染
    var default_avatar = "./img/默认用户头像.jpg"
    var no_default_avatar = "http://www.rushmc.top/" + lg_data.photo;
    if (lg_data.photo === null) {
        console.log(user_profile);
        user_profile.src = default_avatar;
        my_photo_img.src = default_avatar;
        my_trend_top_img.src = default_avatar
    } else {
        user_profile.src = no_default_avatar;
        my_photo_img.src = no_default_avatar;
        my_trend_top_img.src = no_default_avatar;
    }
    //nav头像变化结束
    setTimeout(function () {
        re_lg.style.display = 'none';
    }, 2000);
    var lg_data_length = get_attribute(lg_data);
    let lg_data_keys = Object.keys(lg_data);
    console.log(lg_data_keys);
    console.log(lg_data.photo);
    //渲染用户信息及头像
    for (let i = 0; i < lg_data_length; i++) {
        account_inputs[1].value = lg_data.id;
        account_inputs[2].value = lg_data.username;
        account_inputs[3].value = lg_data.password;
        account_inputs[4].value = lg_data.phone;
        account_inputs[5].value = lg_data.name;
    }
    //请求个人动态
    ajax_request("http://www.rushmc.top/api/dynamicState/select/" + lg_data.id, "get", lg_data.id);
    //登录了才有个人动态
}
//登录成功之后页面变化结束

// function setDate(mydata) {
//     //先清空原来的tbody里面的数据
//     tbody.innerHTML = '';
//     mydata.forEach(function (value) {
//         //console.log(value);
//         var tr = document.createElement('tr');
//         tr.innerHTML = '<td>' + value.id + '</td><td>' + value.pname + '</td><td>' +
//             value.price + '</td>';
//         tbody.appendChild(tr);
//     })
// }
//登录成功之后页面变化结束
